#!/bin/sh

# program AppDir
echo -n "Location for program directory (/usr/local/apps/System): "
read LOCATION
[ "$LOCATION" = "" ] && LOCATION="/usr/local/apps/System"
[ -d $LOCATION/Setup ] && rm -R $LOCATION/Setup
cd apps
for FILE in `find Setup | grep -v .svn`
do
 if [ ! "`file $FILE | grep directory`" = "" ];then
  mkdir -p $LOCATION/$FILE
 else
  cp -af $FILE $LOCATION/$FILE
 fi
done
cd ../
echo -n "Choose PREFIX (/usr): "
read PREFIX
[ "$PREFIX" = "" ] && PREFIX="/usr"
export PREFIX="$PREFIX"
if [ ! -d "$PREFIX" ];then
 echo "ERROR: $PREFIX does not exist!"
 exit 1
fi
# wrapper script
echo "Installing scripts into $PREFIX/sbin"
[ ! -d ${PREFIX}/sbin ] && mkdir -p ${PREFIX}/sbin
cat sbin/controlpanel | sed "s*programpath*$LOCATION/Setup/AppRun*" > ${PREFIX}/sbin/controlpanel
chmod +x ${PREFIX}/sbin/controlpanel
# .desktop file
if [ $PREFIX = $HOME ];then
 XDGDIR=$HOME/.local/share/applications
else
 XDGDIR=${PREFIX}/share/applications
fi
cp -af share/controlpanel.desktop $XDGDIR/controlpanel.desktop
